package com.oopnet.template.test.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class JDKThreadPool implements Runnable{
	private String str="a";
	
	public JDKThreadPool(String str) {
		this.str=str;
	}
	
	public static void main(String[] args) {
		BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(5);
		Executor executor2 = Executors.newSingleThreadExecutor();
		executor2.execute(new JDKThreadPool("Hello"));
		ThreadPoolExecutor executor = new ThreadPoolExecutor(
				4, 10, 1, TimeUnit.DAYS, blockingQueue);
		for (int i = 0; i < 10; i++) {
			executor.execute(new JDKThreadPool(Thread.currentThread().toString()+i));
//			System.out.println(blockingQueue.size());
		}
		for (int i = 0; i < 10; i++) {
			blockingQueue.add(new JDKThreadPool("新加"+i) );
		}
//		executor.shutdown();
	}

	@Override
	public void run() {
		System.out.println(str);
	}
}
